import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
}
export function login(data: LoginData) {
  return axios.post<LoginRes>('/api/user/login', data);
}

export function getNewUserInfo(data){
  return axios.post<UserState>('/api/user/getUserInfo', data);
}

export function logout() {
  return axios.post<LoginRes>('/api/user/logout');
}

export function registerUser(data) {
  return axios.post('/api/user/register', data);
}

export function getAllAccount(params){
  return axios.post('/api/user/getAllAccount', params);
}

export function getUserInfo() {
  return {
    code: 200,
    data: {
      name: 'admin',
      avatar:
        '//lf1-xgcdn-tos.pstatp.com/obj/vcloud/vadmin/start.8e0e4855ee346a46ccff8ff3e24db27b.png',
      email: 'wangliqun@email.com',
      job: 'frontend',
      jobName: '前端艺术家',
      organization: 'Frontend',
      organizationName: '前端',
      location: 'beijing',
      locationName: '北京',
      introduction: '人潇洒，性温存',
      personalWebsite: 'https://www.arco.design',
      phone: '150****0000',
      registrationDate: '2013-05-10 12:10:00',
      accountId: '15012312300',
      certification: 1,
      role: 'admin',
    },
    message: '操作成功',
  }
  return axios.post<UserState>('/api/user/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}
